#pragma once


// short
// Network Package Type -- NPT
// RNPT -- Responsed Network Package Type.
#define NPT_REGISTRY			101
#define RNPT_REGISTRY			102

#define NPT_LOGIN				111
#define RNPT_LOGIN				112

#define NPT_MESSAGE				151
#define RNPT_MESSAGE			152
#define NPT_MESSAGE_ALL			161
#define RNPT_MESSAGE_ALL		162

#define NPT_TERMINAL			181
#define RNPT_TERMINAL			182

#define NPT_LOGOUT				201
#define RNPT_LOGOUT				202

#define NPT_TERM_SERVER			211


// reg: type|name|pwd|....
// login: type|name|pwd
// info: type|name|pwd|...
// msg: type|toid|fromid|msg

struct CMPHeader
{
	int _bodylength;
	unsigned char _type;
};
struct CMPBodyLogin
{
	int nlen;
	char *name;
	int plen;
	char *pwd;
};
struct CMPBodyTerm
{
	int cmd;
};
struct CMPBodyRegistry
{
	int nlen;
	char *name;
	int plen;
	char *pwd;;
};
struct CMPBodyMessage
{
	int toid;
	int fromid;
	int msglen;
	char *msg;
};

class CMyProtocol
{
public:
	CMyProtocol(void);
	~CMyProtocol(void);

public:
	void Register_read(IN char *streambuf, OUT char *name, OUT char *pwd);
	void Register_write(OUT char *streambuf, OUT int &len, IN char *name, IN char *pwd);

	void Message_read();
	void Message_write(OUT char *streambuf, OUT int &length, int toUser, int fromUser, IN char *lpszMsg);

	void Login_read(IN char *streambuf, OUT char *name, OUT char *pwd);
	void Login_write(OUT char *streambuf, OUT int &len, IN char *name, IN char *pwd);

	void Logout_read();
	void Logout_write(OUT char *streambuf, OUT int &length, int uid);

	void Term_write(OUT char *streambuf, OUT int &length);
};

